package cn.escco.ocr.controller;

import cn.escco.ocr.dto.pa.AcquirePlatsParam;
import cn.escco.ocr.dto.pa.JybLoadDataParam;
import cn.escco.ocr.dto.vo.*;
import cn.escco.ocr.service.JybCoreService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/jyb/core/plat")
@CrossOrigin("*")
public class JybCoreController extends BaseController {

    @RequestMapping(value = "/acquireplatplayhdcps", method = {RequestMethod.POST})
    public RespVo<PlatPlayHdcpListVo> acquirePlatPlayHdcps(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        if (StringUtils.isEmpty(param.getPlatCode()))
            throw new RuntimeException("平台编码不能为空！");

        if (StringUtils.isEmpty(param.getTypeCode()))
            throw new RuntimeException("分类编码不能为空！");

        if (StringUtils.isEmpty(param.getLeaCode()))
            throw new RuntimeException("联赛编码不能为空！");

        if (StringUtils.isEmpty(param.getTeamCodeLeft()))
            throw new RuntimeException("左侧球队编码不能为空！");

        if (StringUtils.isEmpty(param.getTeamCodeRight()))
            throw new RuntimeException("右侧球队编码不能为空！");

        if (StringUtils.isEmpty(param.getPlayCode()))
            throw new RuntimeException("玩法编码编码不能为空！");

        if (StringUtils.isEmpty(param.getAcquireFlag()))
            throw new RuntimeException("获取标识不能为空【Y：初期、N：后续】！");

        if (StringUtils.isEmpty(param.getTimeStampPre()) && "N".equals(param.getAcquireFlag()))
            throw new RuntimeException("非初期加载，上一次获取时间戳需要传入！");

        PlatPlayHdcpListVo platPlayHdcpListVo = jybCoreService.acquirePlatPlayHdcps(param.getBaseDate(),
                param.getPlatCode(), param.getTypeCode(), param.getLeaCode(), param.getTeamCodeLeft(),
                param.getTeamCodeRight(), param.getPlayCode(), param.getAcquireFlag(), param.getTimeStampPre());

        RespVo<PlatPlayHdcpListVo> respVo = new RespVo<>();
        respVo.setResult(platPlayHdcpListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquireplatplays", method = {RequestMethod.POST})
    public RespVo<PlatPlayListVo> acquirePlatPlays(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        if (StringUtils.isEmpty(param.getPlatCode()))
            throw new RuntimeException("平台编码不能为空！");

        if (StringUtils.isEmpty(param.getTypeCode()))
            throw new RuntimeException("分类编码不能为空！");

        if (StringUtils.isEmpty(param.getLeaCode()))
            throw new RuntimeException("联赛编码不能为空！");

        if (StringUtils.isEmpty(param.getTeamCodeLeft()))
            throw new RuntimeException("左侧球队编码不能为空！");

        if (StringUtils.isEmpty(param.getTeamCodeRight()))
            throw new RuntimeException("右侧球队编码不能为空！");

        List<PlatPlayVo> platPlayVoList = jybCoreService.acquirePlatPlays(param.getBaseDate(), param.getPlatCode(),
                param.getTypeCode(), param.getLeaCode(), param.getTeamCodeLeft(), param.getTeamCodeRight());
        PlatPlayListVo platPlayListVo = new PlatPlayListVo();
        platPlayListVo.setPlatPlayVoList(platPlayVoList);
        RespVo<PlatPlayListVo> respVo = new RespVo<>();
        respVo.setResult(platPlayListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquireplattypeleateamvss", method = {RequestMethod.POST})
    public RespVo<PlatTypeLeaTeamVsListVo> acquirePlatTypeLeaTeamVss(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        if (StringUtils.isEmpty(param.getPlatCode()))
            throw new RuntimeException("平台编码不能为空！");

        if (StringUtils.isEmpty(param.getTypeCode()))
            throw new RuntimeException("分类编码不能为空！");

        if (StringUtils.isEmpty(param.getLeaCode()))
            throw new RuntimeException("联赛编码不能为空！");

        List<PlatTypeLeaTeamVsVo> platTypeLeaTeamVsVoList = jybCoreService.acquirePlatTypeLeaTeamVss(
                param.getBaseDate(), param.getPlatCode(), param.getTypeCode(), param.getLeaCode());
        PlatTypeLeaTeamVsListVo platTypeLeaTeamVsListVo = new PlatTypeLeaTeamVsListVo();
        platTypeLeaTeamVsListVo.setPlatTypeLeaTeamVsVoList(platTypeLeaTeamVsVoList);
        RespVo<PlatTypeLeaTeamVsListVo> respVo = new RespVo<>();
        respVo.setResult(platTypeLeaTeamVsListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquireplattypeleas", method = {RequestMethod.POST})
    public RespVo<PlatTypeLeaListVo> acquirePlatTypeLeas(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        if (StringUtils.isEmpty(param.getPlatCode()))
            throw new RuntimeException("平台编码不能为空！");

        if (StringUtils.isEmpty(param.getTypeCode()))
            throw new RuntimeException("分类编码不能为空！");

        List<PlatTypeLeaVo> platTypeLeaVoList = jybCoreService.acquirePlatTypeLeas(param.getBaseDate(),
                param.getPlatCode(), param.getTypeCode());
        PlatTypeLeaListVo platTypeLeaListVo = new PlatTypeLeaListVo();
        platTypeLeaListVo.setPlatTypeLeaVoList(platTypeLeaVoList);
        RespVo<PlatTypeLeaListVo> respVo = new RespVo<>();
        respVo.setResult(platTypeLeaListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquireplattypes", method = {RequestMethod.POST})
    public RespVo<PlatTypeListVo> acquirePlatTypes(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        if (StringUtils.isEmpty(param.getPlatCode()))
            throw new RuntimeException("平台编码不能为空！");

        List<PlatTypeVo> platTypeVoList = jybCoreService.acquirePlatTypes(param.getBaseDate(), param.getPlatCode());
        PlatTypeListVo platTypeListVo = new PlatTypeListVo();
        platTypeListVo.setPlatTypeVoList(platTypeVoList);
        RespVo<PlatTypeListVo> respVo = new RespVo<>();
        respVo.setResult(platTypeListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquireplats", method = {RequestMethod.POST})
    public RespVo<PlatListVo> acquirePlats(@RequestBody AcquirePlatsParam param) {

        if (StringUtils.isEmpty(param.getBaseDate()))
            throw new RuntimeException("基准日期不能为空！");

        List<PlatVo> platVoList = jybCoreService.acquirePlats(param.getBaseDate());
        PlatListVo platListVo = new PlatListVo();
        platListVo.setPlatVoList(platVoList);
        RespVo<PlatListVo> respVo = new RespVo<>();
        respVo.setResult(platListVo);

        return respVo;
    }

    @RequestMapping(value = "/acquirebasedates", method = {RequestMethod.POST})
    public RespVo<List<String>> acquireBaseDates() {

        List<String> baseDateList = jybCoreService.getBaseDates();
        RespVo<List<String>> respVo = new RespVo<>();
        respVo.setResult(baseDateList);

        return respVo;
    }

    @RequestMapping(value = "/loaddatas", method = {RequestMethod.POST})
    public RespVo<String> loadDatas(@RequestBody JybLoadDataParam loadData) {

        jybCoreService.loadDatas(loadData);

        return new RespVo<>();
    }

    @Resource
    private JybCoreService jybCoreService;
}
